import {UpdateUserBO, SysUserVo, SysUserInfoVo, RegionNode, OrganizationNode} from './types'
import request from '@/service/request'
import {PromisePageResponse, PromiseResponse} from "@/service/api/type.ts";

/**
 * 获取List数据
 * @param query
 */
const getUserList = (query: any): PromisePageResponse<SysUserVo> => {
  return request({
    url: '/system/user/list',
    method: 'get',
    params: query
  });
};

/**
 * 添加用户
 * @param query
 */
const userAdd = (query: any): PromiseResponse<any> => {
  return request({
    url: '/system/user',
    method: 'post',
    data: query
  })
};

/**
 * 查询详情
 * @param userId
 */
const getUserDetail = (userId: string): PromiseResponse<SysUserInfoVo> => {
  return request({
    url: `/system/user/${userId}`,
    method: 'get'
  });
};

/**
 * 修改详情
 * @param data
 */
const updateUser = (data: UpdateUserBO): PromiseResponse<any> => {
  return request({
    url: '/system/user/edit',
    method: 'put',
    data: data
  });
};

/**
 * 删除测用户
 * @param id
 */
const deleteUser = (id: string | Array<string>): PromiseResponse<any> => {
  return request({
    url: `/system/user/${id}`,
    method: 'delete'
  });
};

/**
 * 获取区域树
 */
const getDefaultRegionTree = (): PromiseResponse<RegionNode[]> => {
  return request({
    url: '/region/treeselect',
    method: 'get'
  });
};

/**
 * 获取组织树
 * @param query
 */
const getOrganizationTree = (query?:any): PromisePageResponse<OrganizationNode> => {
  return request({
    url: "/system/organization/treeselect",
    method: 'get',
    params: query
  });
};

/**
 * 上传excel
 * @param formData
 */
const importExcel = (formData: any): PromiseResponse<any> => {
  return request({
    url: "/system/user/importData",
    method: 'post',
    data: formData
  });
};

/**
 * 修改密码
 * @param query
 */
const changePassword = (query: any): PromiseResponse<any> => {
  return request({
    url: "/system/user/resetPwd",
    method: 'put',
    data: query
  });
}

export {
  getUserList,
  userAdd,
  getUserDetail,
  updateUser,
  deleteUser,
  getDefaultRegionTree,
  getOrganizationTree,
  importExcel,
  changePassword
};
